package weaver.interfaces.qz.job;

import com.engine.qz.service.impl.CommissionServiceImpl;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.schedule.BaseCronJob;

import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Title ecology-9
 * @Company 泛微软件
 * @CreateDate 2025/8/5
 * @Description 员工提成生成
 * @Author AdminZm
 */
public class GenerateCommissionPlanJob extends BaseCronJob {

    BaseBean baseBean = new BaseBean();

    @Override
    public void execute() {
        baseBean.writeLog("GenerateCommissionPlanJob start.");
        int dayOfMonth = LocalDate.now().getDayOfMonth();
        YearMonth ny = YearMonth.now();
        YearMonth sy = ny.minusMonths(1);
        List<String> yfList = new ArrayList<>();
        yfList.add(ny.toString());
        if (dayOfMonth <= 5) {
            yfList.add(sy.toString());
        }
        baseBean.writeLog("GenerateCommissionPlanJob yfList:" + yfList);
        CommissionServiceImpl commissionServiceImpl = new CommissionServiceImpl();
        Map<String, Object> params = new HashMap<>();
        for (String yfTemp : yfList) {
            try {
                params = new HashMap<>();
                params.put("ny", yfTemp);
                Map<String, Object> map = commissionServiceImpl.generateCommissionPlan(params);
                baseBean.writeLog("GenerateCommissionPlanJob dt result:" + yfTemp + "、" + map);
            } catch (Exception e) {
                baseBean.writeLog("GenerateCommissionPlanJob dt error:" + yfTemp + "、" + e);
            }
        }
        baseBean.writeLog("GenerateCommissionPlanJob end.");
    }
}
